package com.water.expert.extraction.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
// CRUD refers Create, Read, Update, Delete

public interface ExpertRepository extends CrudRepository<Expert, Long> {
	 @Query("SELECT e FROM Expert e WHERE " +
	           "(:name IS NULL OR e.name LIKE %:name%) AND " +
	           "(:title IS NULL OR e.title LIKE %:title%) AND " +
	           "(:companyName IS NULL OR e.companyName LIKE %:companyName%) AND " +
	           "(:email IS NULL OR e.email LIKE %:email%)")
	    List<Expert> searchExperts(@Param("name") String name,
	                               @Param("title") String title,
	                               @Param("companyName") String companyName,
	                               @Param("email") String email);
	 
	 @Query("SELECT e FROM Expert e WHERE (e.currentProfession=:currentProfession)")
	 List<Expert> getByCurrentProfession(@Param("currentProfession")Profession currentProfession);
}
